﻿using System;

using Microsoft.Practices.Composite.Events;

using Matchingo.Common.Types.Events;
using Matchingo.Common.Types.Interfaces;
using Matchingo.Common.Types.Types;

namespace Matchingo.Controllers.GameInputController
{
    public class GameInputFacade : IGameInputFacade
    {
        private IMemoryGameLogic GameLogic { get; set; }
		private IEventAggregator EventAggregator { get; set; }

        public GameInputFacade(IEventAggregator eventAggregator, IMemoryGameLogic gameLogic)
        {
            GameLogic = gameLogic;
			EventAggregator = eventAggregator;
        }

        public bool FlipCard(Guid uniqueCardID)
        {
            // construct the command
            CardFlipCommand command = new CardFlipCommand(uniqueCardID);
            bool flipped = command.Execute(GameLogic);

			if (flipped)
			{
				EventAggregator.GetEvent<CardFlippedEvent>().Publish(uniqueCardID);
			}

			return flipped;
        }
    }
}
